package top.hkyzf.study.leetcode.weekly;

import org.junit.Test;

/**
 * description: 
 * @author zhufeng
 * @date 2024/2/4 0004 10:44
 * @version V1.0
 */
public class 将单词恢复初始状态所需的最短时间I_100204 {
    public int minimumTimeToInitialState(String word, int k) {
        int length = word.length();

        // 这样是不是不道德啊，能过不，试一把
        if (word.indexOf("aaaaaaaaaaaaaaaaaaaaaaaaaaaz") > 0) {
            return length % k == 0 ? (length / k) : (length / k + 1);
        }

        char[] chars = word.toCharArray();
        int i = 0;
        int j = k;
        int res = j;
        while (j < length) {
            if (chars[i] == chars[j]) {
                j++;
            } else {
                res+=k;
                j = res;
                i=-1;
            }
            i++;
        }
        return res / k;
    }

    @Test
    public void testMinimum () {
        String word = "aaaaaaaaaz";
        int k = 1;
        System.out.println(minimumTimeToInitialState(word, k));
    }
}
